const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const merge = require("webpack-merge");
const webpackBaseConfig = require("./webpack.base.config.js");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const config = require("./config.json");
const proxyConfig = require("./proxyConfig.js");
var path = require("path");

module.exports = merge(webpackBaseConfig, {
  devServer: {
    historyApiFallback: true,
    disableHostCheck: true,
    proxy: proxyConfig
  },
  devtool: "#source-map",
  output: {
    publicPath: "",
    filename: "[name].js",
    chunkFilename: "[name].chunk.js"
  },
  plugins: [
    new ExtractTextPlugin({
      filename: "[name].css",
      allChunks: true
    }),
    new webpack.DefinePlugin({
      "process.env": {
        NODE_ENV: '"development"',
      },
      "appConfig": {
        API: JSON.stringify(config["development"])
      }
    }),
    new HtmlWebpackPlugin({
      // configUrl: "//10.153.107.33:8094/config.js?v=" + Date.now(),
      favicon: "./favicon.ico",
      inject: true,
      filename: "./index.html",
      template: path.join(__dirname, "../src/template/index.ejs")
    }),
    new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, "../static"),
        to: "static",
        ignore: [".*"]
      }
    ])
  ]
});
